home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / oct-alloc.h < prev    next >
C/C++ Source or Header  |  1996-11-07  |  2KB  |  69 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_oct_alloc_h)
  24. #define octave_oct_alloc_h 1
  25.  
  26. class
  27. octave_allocator
  28. {
  29. public:
  30.  
  31.   octave_allocator (size_t item_sz, int grow_sz = 256)
  32.     : head (0), grow_size (grow_sz),
  33.       item_size (item_sz > sizeof (link *) ? item_sz : sizeof (link *))
  34.   { }
  35.  
  36.   // Get an object from the free list, possibly increasing the size of
  37.   // the free list.
  38.   void *alloc (size_t size);
  39.  
  40.   // Put objects back on the free list.
  41.   void free (void *p, size_t size);
  42.  
  43. private:
  44.  
  45.   // Structure for internal free list management.
  46.   struct link { link *next; };
  47.  
  48.   // Front of the free list.
  49.   link *head;
  50.  
  51.   // How many objects to get each time we call the global operator new.
  52.   int grow_size;
  53.  
  54.   // The size of each item on the list (or, if that is smaller than
  55.   // the size of list*, the size of list*.
  56.   size_t item_size;
  57.  
  58.   // How to grow the free list.
  59.   bool grow (void);
  60. };
  61.  
  62. #endif
  63.  
  64. /*
  65. ;;; Local Variables: ***
  66. ;;; mode: C++ ***
  67. ;;; End: ***
  68. */
  69.